import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILockSetPasswordWindow } from "../../../../modules/interfaces/ILockSetPasswordWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { SetPasswordSprite } from "./SetPasswordSprite";
import { SetProtectInfoSprite } from "./SetProtectInfoSprite";
import { ConfirmProtectInfoSprite } from "./ConfirmProtectInfoSprite";
import { LockInfoData } from "./LockInfoData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ELockStatus } from "../../../../Message/Game/ELockStatus";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class LockSetPasswordWindow
    
    export  class LockSetPasswordWindow extends BaseWindow implements ILockSetPasswordWindow
    {
        constructor()
        {
            super();
            setSize(360, 440);
            title = Language.getString(35515);
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            var loc1=ObjCreate.createBg(17, 42, 325, 390, this);
            var loc2=ObjCreate.createBg(90, 50, 180, 25, this, ImagesConst.PopUpMenuOverSkin);
            this._topicTxt = ObjCreate.createTextField("", 140, 55, 200, 20, this);
            this._topicTxt.htmlText = Language.getString(35516);
            this._topicTxt.filters = [];
            this._setPw = new SetPasswordSprite();
            this._setPw.x = 30;
            this._setPw.y = 75;
            this._setProtect = new SetProtectInfoSprite();
            this._setProtect.x = 30;
            this._setProtect.y = 75;
            this._confirmProtect = new ConfirmProtectInfoSprite();
            this._confirmProtect.x = 30;
            this._confirmProtect.y = 75;
            this._prevStepBtn = ObjCreate.createGButton(Language.getString(35517), 90, 400, 70, 25, this);
            this._prevStepBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onPrevStepBtnHandler);
            this._nextStepBtn = ObjCreate.createGButton(Language.getString(35518), 200, 400, 70, 25, this);
            this._nextStepBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onNextStepBtnHandler);
            this._finishBtn = ObjCreate.createGButton(Language.getString(35519), 200, 400, 70, 25, this);
            this._finishBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onFinishBtnHandler);
            this._finishBtn.visible = false;
            return;
        }

        /* internal  */onPrevStepBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (LockInfoData.settingStep != 3) 
            {
                if (LockInfoData.settingStep == 2) 
                {
                    this.removePanel();
                    addChild(this._setPw);
                    --LockInfoData.settingStep;
                    this._prevStepBtn.enabled = true;
                    this._topicTxt.htmlText = Language.getString(35516);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, true));
                }
            }
            else 
            {
                this.removePanel();
                if (LockInfoData.lockStatus.value() != ELockStatus._ELockStatusNULL) 
                {
                    if (LockInfoData.lockStatus.value() == ELockStatus._ELockStatusNoPassword) 
                    {
                        addChild(this._setPw);
                        LockInfoData.settingStep = LockInfoData.settingStep - 2;
                        this._topicTxt.htmlText = Language.getString(35516);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, true));
                    }
                }
                else 
                {
                    addChild(this._setProtect);
                    --LockInfoData.settingStep;
                    this._topicTxt.htmlText = Language.getString(35520);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, false));
                }
                this._finishBtn.visible = false;
                this._nextStepBtn.visible = true;
            }
            return;
        }

        /* internal  */onNextStepBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            if (LockInfoData.settingStep != 1) 
            {
                if (LockInfoData.settingStep == 2) 
                {
                    loc1 = this._setProtect.setProtectInfo();
                    if (loc1) 
                    {
                        this.removePanel();
                        addChild(this._confirmProtect);
                        this._confirmProtect.setQuestion();
                        LockInfoData.settingStep = LockInfoData.settingStep + 1;
                        this._nextStepBtn.visible = false;
                        this._finishBtn.visible = true;
                        this._topicTxt.htmlText = Language.getString(35521);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, false));
                    }
                }
            }
            else 
            {
                loc1 = this._setPw.setPassword();
                if (loc1) 
                {
                    this.removePanel();
                    if (LockInfoData.lockStatus.value() != ELockStatus._ELockStatusNULL) 
                    {
                        if (LockInfoData.lockStatus.value() == ELockStatus._ELockStatusNoPassword) 
                        {
                            addChild(this._confirmProtect);
                            this._nextStepBtn.visible = false;
                            this._finishBtn.visible = true;
                            LockInfoData.settingStep = LockInfoData.settingStep + 2;
                            this._topicTxt.htmlText = Language.getString(35521);
                            if (LockInfoData.questionOne == "" || LockInfoData.questionTwo == "") 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.LockGetQuestion));
                            }
                            else 
                            {
                                this._confirmProtect.setQuestion();
                            }
                            this._isNoPassword = true;
                            Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, false));
                        }
                    }
                    else 
                    {
                        addChild(this._setProtect);
                        LockInfoData.settingStep = LockInfoData.settingStep + 1;
                        this._topicTxt.htmlText = Language.getString(35520);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, false));
                    }
                    this._prevStepBtn.enabled = true;
                }
            }
            return;
        }

        /* internal  */onFinishBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isNoPassword) 
            {
                this._confirmProtect.setPassWord();
            }
            else 
            {
                this._confirmProtect.confirmProtectInfo();
            }
            return;
        }

        /* internal  */removePanel(): void
        {
            if (this._setPw.parent) 
            {
                removeChild(this._setPw);
            }
            else if (this._setProtect.parent) 
            {
                removeChild(this._setProtect);
            }
            else if (this._confirmProtect.parent) 
            {
                removeChild(this._confirmProtect);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.removePanel();
            LockInfoData.settingStep = 1;
            addChild(this._setPw);
            this._prevStepBtn.enabled = false;
            this._finishBtn.visible = false;
            this._nextStepBtn.visible = true;
            this._topicTxt.htmlText = Language.getString(35516);
            Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, true));
            Dispatcher.addEventListener(EventName.LockNumberKeyboardChange, this.onNumberKeyboardChangeHandler);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._setPw.resetSprite();
            this._setProtect.resetSprite();
            this._confirmProtect.resetSprite();
            Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, false));
            Dispatcher.removeEventListener(EventName.LockNumberKeyboardChange, this.onNumberKeyboardChangeHandler);
            return;
        }

        public setQuestion(): void
        {
            this._confirmProtect.setQuestion();
            return;
        }

        /* internal  */onNumberKeyboardChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            if (this._setPw && this._setPw.parent) 
            {
                this._setPw.numberKeyboardChange(loc1);
            }
            return;
        }

        /* internal */ /* var */_topicTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_setPw: SetPasswordSprite;

        /* internal */ /* var */_setProtect: SetProtectInfoSprite;

        /* internal */ /* var */_confirmProtect: ConfirmProtectInfoSprite;

        /* internal */ /* var */_nextStepBtn: GButton;

        /* internal */ /* var */_prevStepBtn: GButton;

        /* internal */ /* var */_finishBtn: GButton;

        /* internal */ /* var */_isNoPassword: Boolean=false;
    }
